from Cheetah.Template import Template
from schema import schema
import util

class UIBase:
    def __init__(self):
        self.macro_chart_mount = 'macros_chart_mount.tmp'

    def get_structure(self, structure, **wargs):
        context = {'tables_names': None,
                   'columns': None
                  }
        if structure == 'tables_names':
            tables_names = schema.keys()
            context.update(dict(tables_names = tables_names))

        if structure == 'columns':
            columns = [col.name for col in schema[wargs.get('object_id')].columns]
            context.update(dict(columns = columns))
        
        if structure == 'columns_datetime':
            columns = [col.name for col in schema[wargs.get('object_id')].columns if util.is_date(col)]
            context.update(dict(columns = columns))

        if structure == 'columns_number':
            columns = [col.name for col in schema[wargs.get('object_id')].columns if util.is_number(col)]
            context.update(dict(columns = columns))
        return str(Template(open(self.macro_chart_mount).read(), namespaces=context))
    get_structure.exposed = True
